#!/usr/bin/env node
/* 列出 pph_records 表列清单 */
const path = require('path');
const sqlite3 = require('sqlite3').verbose();

const dbPath = path.join(__dirname, '..', 'data', 'pph.sqlite');
const db = new sqlite3.Database(dbPath);

function all(sql) { return new Promise((resolve, reject) => db.all(sql, (err, rows) => err ? reject(err) : resolve(rows))); }

(async () => {
  try {
    const rows = await all('PRAGMA table_info(pph_records)');
    const cols = (rows || []).map(r => ({ cid: r.cid, name: r.name, type: r.type, notnull: r.notnull, dflt_value: r.dflt_value }));
    console.log(JSON.stringify({ success: true, columns: cols }, null, 2));
  } catch (e) {
    console.error(JSON.stringify({ success: false, error: e.message }));
    process.exit(1);
  } finally {
    db.close();
  }
})();
